using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Data; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using SolucionUtiles; 
using SolucionEntidad; 
namespace SolucionDatos 
{ 
   public class PersonaJuridicaDao 
    { 
        private SqlConnection cn; 
        public PersonaJuridicaDao(SqlConnection cn) 
        { 
           this.cn = cn; 
        } 
        public void insert(PersonaJuridica obj)
        { 
           SqlCommand command = new SqlCommand("INSERT INTO persona_juridica " + 
           "(idPersona,entidadBancaria,cuentaBancaria,numeroRuc) VALUES" + 
           "(@idPersona,@entidadBancaria,@cuentaBancaria,@numeroRuc)", this.cn); 

command.Parameters.Add(new SqlParameter("@idPersona", obj.idPersona)); 
command.Parameters.Add(new SqlParameter("@entidadBancaria", obj.entidadBancaria)); 
command.Parameters.Add(new SqlParameter("@cuentaBancaria", obj.cuentaBancaria)); 
command.Parameters.Add(new SqlParameter("@numeroRuc", obj.numeroRuc)); 
command.ExecuteNonQuery(); 
} 
  		public void update(PersonaJuridica obj) 
    	{ 
        	SqlCommand command = new SqlCommand("UPDATE PersonaJuridica " + 
			" SET " + 
"entidadBancaria=@entidadBancaria" + 
",cuentaBancaria=@cuentaBancaria" + 
",numeroRuc=@numeroRuc" + 
 " WHERE " + 
"idPersona=@idPersona" 
,this.cn); 
command.Parameters.Add(new SqlParameter("@idPersona", obj.idPersona)); 
command.Parameters.Add(new SqlParameter("@entidadBancaria", obj.entidadBancaria)); 
command.Parameters.Add(new SqlParameter("@cuentaBancaria", obj.cuentaBancaria)); 
command.Parameters.Add(new SqlParameter("@numeroRuc", obj.numeroRuc)); 
command.ExecuteNonQuery(); 
} 
       public void delete(PersonaJuridica obj){ 
SqlCommand command = new SqlCommand("DELETE FROM persona_juridica WHERE "  
 +"idPersona=@idPersona" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idPersona", obj.idPersona)); 
command.ExecuteNonQuery(); 
} 
        public PersonaJuridica get(PersonaJuridica obj) 
{ 
   PersonaJuridica record = null; 
    SqlCommand command = new SqlCommand("SELECT idPersona,entidadBancaria,cuentaBancaria,numeroRuc FROM persona_juridica where " 
 +"idPersona=@idPersona" 
, this.cn); 
command.Parameters.Add(new SqlParameter("@idPersona", obj.idPersona)); 

    SqlDataReader dr = command.ExecuteReader();
dr.Read(); 
record = new PersonaJuridica(); 
if (dr["idPersona"] == DBNull.Value) { record.idPersona = SqlInt32.Null; } else { record.idPersona = (Int32)dr["idPersona"]; } 
if (dr["entidadBancaria"] == DBNull.Value) { record.entidadBancaria = SqlString.Null; } else { record.entidadBancaria = (String)dr["entidadBancaria"]; } 
if (dr["cuentaBancaria"] == DBNull.Value) { record.cuentaBancaria = SqlString.Null; } else { record.cuentaBancaria = (String)dr["cuentaBancaria"]; } 
if (dr["numeroRuc"] == DBNull.Value) { record.numeroRuc = SqlString.Null; } else { record.numeroRuc = (String)dr["numeroRuc"]; } 
this.cn.Close(); 
return record; 
} 
     public List<PersonaJuridica> getList() 
{ 
   List<PersonaJuridica> list = new List<PersonaJuridica>(); 
    SqlCommand command = new SqlCommand("SELECT idPersona,entidadBancaria,cuentaBancaria,numeroRuc FROM persona_juridica", this.cn); 
    SqlDataReader dr = command.ExecuteReader(); 
    while (dr.Read()) 
    { 
PersonaJuridica obj = new PersonaJuridica(); 
if (dr["idPersona"] == DBNull.Value) { obj.idPersona = SqlInt32.Null; } else { obj.idPersona = (Int32)dr["idPersona"]; } 
if (dr["entidadBancaria"] == DBNull.Value) { obj.entidadBancaria = SqlString.Null; } else { obj.entidadBancaria = (String)dr["entidadBancaria"]; } 
if (dr["cuentaBancaria"] == DBNull.Value) { obj.cuentaBancaria = SqlString.Null; } else { obj.cuentaBancaria = (String)dr["cuentaBancaria"]; } 
if (dr["numeroRuc"] == DBNull.Value) { obj.numeroRuc = SqlString.Null; } else { obj.numeroRuc = (String)dr["numeroRuc"]; } 
list.Add(obj); 
} 
return list; 
} 
} 
} 
